package boot

import (
	"gitee.com/worklz/grpc-mtls-demo/gateway/app/middleware"
	"gitee.com/worklz/grpc-mtls-demo/gateway/pkg/global"
	"gitee.com/worklz/grpc-mtls-demo/gateway/router"
	"github.com/gin-gonic/gin"
)

// InitRoute 初始化路由
func InitRoute() {
	gin.SetMode("debug")
	r := gin.Default()

	// 中间件
	r.Use(
		middleware.CORS(),
		gin.RecoveryWithWriter(gin.DefaultErrorWriter, func(c *gin.Context, recovered any) {
			middleware.Recover(c, recovered)
		}),
	)

	// 路由
	router.Router(r)

	global.GinEngine = r
}
